<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="{{asset('layui-v2.6.8/layui/css/layui.css')}}">
    <script src="{{asset('js/jquery.min.js')}}"></script>
    <script src="{{asset('layui-v2.6.8/layui/layui.js')}}"></script>
    <title>好友列表</title>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>好友列表</legend>
</fieldset>
<div class="layui-form">
    <table class="layui-table">
        <colgroup>
            <col width="150">
            <col width="150">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>好友</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        @foreach($data as $k=>$v)
            <tr>
                <td>tel:{{$v->_imUserHasOne['tel']}}</td>
                <td>
                    <div class="layui-btn-group">
                        <a href="{{route('im.chat',$v['friend_id'])}}" class="layui-btn">发起聊天</a>
                        <a href="javascript:;" class="layui-btn" onclick="del({{$v['id']}},this)">删除好友</a>
                        <form action="{{route('im.deleteFriends',$v['id'])}}" hidden method="post">
                            @csrf
                        </form>
                    </div>
                </td>
            </tr>
        @endforeach
        {{$data->links()}}
        </tbody>
    </table>
</div>

<hr>

<form class="layui-form" action="{{route('im.addFriends')}}" method="post">
    @csrf
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">添加好友</label>
            <div class="layui-input-inline">
                <input type="tel" name="tel" lay-verify="required" autocomplete="off" class="layui-input"
                       placeholder="请输入手机号">
            </div>
        </div>
        <div class="layui-inline">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate

        form.render(); //更新全部
    });

    //删除
    function del(id, el) {
        //询问框
        layer.confirm('确认删除吗？', {
            btn: ['确认', '取消'] //按钮
        }, function (index) {
            $(el).next('form').trigger('submit')
        });
    }
</script>
</html>